home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.express.ca!not-for-mail
- From: gchan@express.ca (Gary Chan)
- Subject: function to format float number
- Message-ID: <367cc$0321.121@news.express.ca>
- Date: Wed, 06 Mar 1996 08:50:01 GMT
- X-Newsreader: WinVN 0.99.6
- MIME-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
-
- I need a function to convert a floating point number to a formatted
- dollar value string. Eg. 1234 becomes $1,234.00
-
- I need help implementing my "cformat" function:
-
- #include <stdio.h>
- #include <ctype.h>
- #define MAX_STRLEN 20 //maximum length of input string
- #define NONUM 0
- #define YESNUM 1
-
- int GetFloat(float *n);
- char cformat(float n, char buff);
- int main()
-
- {
- float number;
- int status;
- char buff[MAX_STRLEN + 1];
-
- printf("\n\nEnter a number: ");
- status = GetFloat(&number);
-
- //printf("Status is %d", status);
- switch(status)
- {
- case YESNUM: cformat(number, *buff);
- printf("The formatted number is
- %s\n", buff);
- break;
- case NONUM: printf("Cannot format\n");
- break;
- default: break;
- }
-
-
-
- return(0);
- }
-
- char cformat(float n, char *buff)
-
- {
- ???
- }
- *******************
- Thanks in advance.
-
-
-